<!--  -->
<template>
  <div class="app-container">
    <div>
      <router-link to="/university/expert">
        <el-button type="text" icon="el-icon-arrow-left" size="default"
          >返回</el-button
        >
      </router-link>
    </div>
    <el-table :data="tableData" border stripe>
      <el-table-column
        type="selection"
        width="60"
        align="center"
      ></el-table-column>

      <template v-for="(i, index) in columns">
        <el-table-column
          v-if="index == 4"
          :key="i.id"
          :label="i.label"
          align="center"
          :width="i.width"
        >
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.payment"
              :active-value="1"
              :inactive-value="2"
              @change
            ></el-switch>
          </template>
        </el-table-column>

        <el-table-column
          v-else
          :prop="i.data"
          :key="i.id"
          :label="i.label"
          align="center"
          :width="i.width"
        />
      </template>
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-edit" @click="edit(scope.row)"
            >编辑</el-button
          >
          <el-button
            type="text"
            icon="el-icon-delete"
            style="color: #f66"
            @click="del(scope.$index)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div class="page">
      <el-pagination
        @size-change="sizeChange"
        @current-change="currentChange"
        :current-page.sync="page"
        :page-sizes="[20, 40, 80, 100]"
        :page-size="limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      ></el-pagination>
    </div>

    <!-- 对话框 -->
    <el-dialog
      title="新增"
      :visible.sync="showDialog"
      width="40%"
      @close="showDialog = false"
    >
      <el-form v-model="form" label-width="180px" :inline="false" size="normal">
        <el-form-item label="分类编号">
          <el-input v-model="form.id" style="width: 220px"></el-input>
        </el-form-item>
        <el-form-item label="分类名称">
          <el-input v-model="form.name" style="width: 220px"></el-input>
        </el-form-item>
        <el-form-item label="分类信息">
          <el-input v-model="form.info" style="width: 220px"></el-input>
        </el-form-item>
        <el-form-item label="首页排序">
          <el-input v-model="form.homeIndex" style="width: 220px"></el-input>
        </el-form-item>
        <el-form-item label="是否推荐至专家首页">
          <el-switch
            v-model="form.inExp"
            :active-value="1"
            :inactive-value="0"
          />
        </el-form-item>
        <el-form-item label="专家首页排序">
          <el-input v-model="form.expIndex" style="width: 220px"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer">
        <el-button @click="showDialog = false">取消</el-button>
        <el-button type="primary" @click>确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "slider",
  data() {
    return {
      mId: "",
      mName: "",
      keyword: "",
      page: 1,
      limit: 10,
      total: 10,
      dialogTitle: "创建",
      showDialog: false,
      form: {
        subTime: "",
        subShop: "",
        subCount: "",
        subPayment: "",
      },
      tableData: [
        {
          id: "3",
          name: "2021-02-21",
          info: "生日模板",
          homeIndex: 1,
          inExp: 20,
          expIndex: 40,
        },
        {
          id: "3",
          name: "2021-02-21",
          info: "生日模板",
          homeIndex: 1,
          inExp: 20,
          expIndex: 40,
        },
        {
          id: "3",
          name: "2021-02-21",
          info: "生日模板",
          homeIndex: 1,
          inExp: 20,
          expIndex: 40,
        },
      ],

      columns: [
        { key: 0, label: `分类编号`, data: "id", width: "80" },
        { key: 1, label: `分类名称`, data: "name" },
        { key: 2, label: `分类信息`, data: "info" },
        { key: 3, label: `首页排序`, data: "homeIndex" },
        { key: 4, label: `是否推荐至专家首页`, data: "inExp" },
        { key: 5, label: `专家首页排序`, data: "expIndex" },
      ],
    };
  },
  created() {},
  methods: {
    add() {
      this.form = {};
      this.showDialog = true;
    },
    edit(i) {
      this.form = {};
      this.showDialog = true;
    },
    del(i) {
      this.$confirm("确认删除所选数据？", "确认删除", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.tableData.splice(i, 1);
        })
        .catch(() => {});
    },

    sizeChange() {},
    currentChange() {},
  },
};
</script>
<style scoped>
.slideImg {
  width: 140px;
}
</style>
